﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Highchart.Core;
using Highchart.Core.Options;
using Highchart.Core.PlotOptions;
using Highchart.Core.ScriptServices;

namespace Highchart.UI
{
    public class PieChart : Chart, IChart
    {

        protected override void OnPreRender(EventArgs e)
        {
            Render();
        }

        public PlotOptionsPie PlotOptions
        {
            get
            {
                object o = ViewState["PlotOptionsPie"];
                if (o == null)
                    return new PlotOptionsPie();
                return (PlotOptionsPie)o;
            }
            set { ViewState["PlotOptionsPie"] = value; }
        }

        public void Render()
        {

            var chartOptions = new ChartOptions
            {
                ClientId = ClientID,
                Lang = Lang,
                Appearance = Appearance,
                Colors = Colors,
                RenderType = RenderType,
                Legend = Legend,
                Exporting = Exporting,
                ShowCredits = ShowCredits,
                Title = Title,
                SubTitle = SubTitle,
                Tooltip = new ToolTip(ToolTip),
                YAxis = YAxis,
                XAxis = XAxis,
                Series = Series,
                Theme = Theme,
                AjaxDataSource = AjaxDataSource,
                PlotOptions = PlotOptions
            };

            var pieChartScript = ScriptBuilder.BuildPieChart(chartOptions);

            System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "chart_" + ClientID, pieChartScript, true);
                        
        }

    }
}
